<template>
  <div class="wrap">
    <header>
      <span @click="go">&lt;</span>
      <h4>租房</h4>
      <!-- <img src="../../img/雪碧图.png" alt /> -->
    </header>
    <main>
      <div class="esf">
        <!-- 导航 -->
        <div class="search">
          <p @click="tocity" class="citysize">{{city}}</p>
          <div class="input">
            <input type="text" placeholder="请在这里输入区域/商圈" />
            <van-icon name="search" />
          </div>
          <span @click="mapfind">地图找房</span>
        </div>
        <!-- tab切换 -->
        <div class="tab">
          <a>
            <img src="../../img/tab1.png" alt />
            <span>找商铺</span>
          </a>
          <a>
            <img src="../../img/tab2.png" alt />
            <span>找写字楼</span>
          </a>

          <a>
            <img src="../../img/tab3.png" alt />
            <span>找小区</span>
          </a>
        </div>
      </div>

      <div class="main-tab">
        <div class="screening">
          <van-dropdown-menu>
            <van-dropdown-item v-model="value1" :options="option1" @change="screening1(value1)" />
            <van-dropdown-item v-model="value2" :options="option2" />
            <van-dropdown-item v-model="value3" :options="option3" @change="screening3(value3)" />
            <van-dropdown-item v-model="value4" :options="option4" @change="screening4(value4)" />
          </van-dropdown-menu>
          <!-- 房子渲染 -->
          <div class="getList">
            <div v-for="(item,idx) in list" :key="idx" class="home" @click="todetail(item)">
              <img src="../../img/home.png" alt />
              <div class="font">
                <h4>{{item.title}}</h4>
                <p class="p">43平/2室 1厅/远洋新天地</p>
                <div class="fonts">
                  <span>{{item.price}}万</span>
                  <p>12100元/m²</p>
                </div>
                <div class="font1">
                  <p class="style">{{item.type}}</p>
                  <p>{{item.desc}}</p>
                  <p>{{item.city}}</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      list: [],
      city: "",
      //筛选数据
      value1: "区域",
      option1: [
        { text: "区域", value: "区域" },
        { text: "北京", value: "北京" },
        { text: "杭州", value: "杭州" },
        { text: "安徽", value: "安徽" },
        { text: "吉林", value: "吉林" }
      ],
      value2: "价格",
      option2: [
        { text: "价格", value: "价格" },
        { text: "1万", value: "万" },
        { text: "20-30万", value: "20-30万" },
        { text: "30-50万", value: "30-50万" },
        { text: "50-100万", value: "50-100万" },
        { text: "100万", value: "100万" }
      ],
      value3: "户型",
      option3: [
        { text: "户型", value: "户型" },
        { text: "别墅", value: "别墅" },
        { text: "二手房", value: "二手房" },
        { text: "酒店", value: "酒店" }
      ],
      value4: "筛选",
      option4: [
        { text: "筛选", value: "筛选" },
        { text: "南", value: "南" },
        { text: "北", value: "北" },
        { text: "东", value: "东" },
        { text: "西", value: "西" }
      ]
    };
  },
  created() {
    this.getList();
    this.city = localStorage.getItem("city") || "北京";
  },
  methods: {
    // 渲染
    getList() {
      axios({
        url: "/api/getList",
        method: "post"
      }).then(res => {
        // console.log(res);
        this.list = res.data.data;
      });
    },
    //户型
    screening3(value) {
      axios({
        url: "/api/screening3",
        method: "post",
        data: {
          value: value
        }
      }).then(res => {
        if (res.data.code === 1) {
          //调用函数
          this.getlist();
        } else {
          this.list = res.data.data;
        }
      });
    },
    //筛选
    screening4(value) {
      axios({
        url: "/api/screening4",
        method: "post",
        data: {
          value: value
        }
      }).then(res => {
        if (res.data.code === 1) {
          //调用函数
          this.getlist();
        } else {
          this.list = res.data.data;
        }
      });
    },
    //区域
    screening1(value) {
      axios({
        url: "/api/screening1",
        method: "post",
        data: {
          value: value
        }
      }).then(res => {
        if (res.data.code === 1) {
          //调用函数
          this.getlist();
        } else {
          this.list = res.data.data;
        }
      });
    },
    go() {
      this.$router.go(-1);
    },
    mapfind() {
      this.$router.push("/map");
    },
    todetail(item) {
      this.$router.push(`/detail/${item.id}`);
    },
    tocity() {
      this.$router.push("/city");
    }
  }
};
</script>

<style lang="scss" scope>
.wrap {
  width: 99.8%;
  height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid #999;
}
header {
  width: 100%;
  height: 50px;
  background: rgb(72, 72, 225);
  display: flex;
  // justify-content: space-between;
  width: 100%;
  height: 50px;
  align-items: center;
  text-align: center;
  color: #fff;
  padding: 20px;
  h4 {
    padding-left: 38%;
  }
  // img {
  //   width: 70px;
  //   height: 30px;
  // }
}
main {
  flex: 1;
  overflow-y: scroll;
  .esf {
    border-bottom: 1px solid #999;
    //导航
    .search {
      width: 90%;
      height: 40px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin: 5% 15px;
      .citysize {
        font-size: 15px;
        color: #333;
      }
      .input {
        height: 30px;
        width: 200px;
        background: #f1f1f1;
        input {
          background: #f1f1f1;
          border: none;
          font-size: 14px;
          padding-left: 6px;
        }
        display: flex;
        align-items: center;
      }
    }
    //tab切换
    .tab {
      width: 85%;
      height: 100px;
      display: flex;
      justify-content: space-around;
      margin: 0 7.5%;
      a {
        align-items: center;
        text-align: center;
        img {
          width: 50px;
          height: 50px;
        }
        span {
          display: block;
          font-size: 16px;
        }
      }
    }
  }
  .getList {
    width: 100%;
    height: 650px;
    overflow: hidden;
    margin-top: 5%;
    border-top: 1px solid #999;
    .home {
      display: flex;
      margin: 10px 0;
      padding: 10px;
      img {
        width: 120px;
        height: 80px;
      }
      .font {
        padding-left: 10px;
        align-items: center;
        .p {
          font-size: 14px;
        }
        .fonts {
          display: flex;
          align-items: center;

          span {
            color: rgb(247, 136, 25);
            font-size: 14px;
          }
          p {
            padding-left: 8px;
            font-size: 14px;
          }
        }
        .font1 {
          display: flex;
          align-items: center;
          .style {
            width: 50px;
            height: 22px;
            background: #ccc;
            font-size: 14px;
            margin-right: 8px;
          }
          p {
            font-size: 16px;
            padding: 0 4px;
          }
        }
      }
    }
  }
}
</style>